home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / DXTex / dialogs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  8.2 KB  |  323 lines

  1. // Dialogs.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "dxtex.h"
  6. #include "formats.h"
  7. #include "dialogs.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15.  
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CNewTextureDlg dialog
  19.  
  20.  
  21. CNewTextureDlg::CNewTextureDlg(CWnd* pParent /*=NULL*/)
  22.     : CDialog(CNewTextureDlg::IDD, pParent)
  23. {
  24.     //{{AFX_DATA_INIT(CNewTextureDlg)
  25.     m_iTexType = 0;
  26.     m_dwWidth = 256;
  27.     m_dwHeight = 256;
  28.     m_dwDepth = 8;
  29.     m_iFmt = 0;
  30.     m_strFmtDesc = _T("");
  31.     m_numMips = 1;
  32.     //}}AFX_DATA_INIT
  33.  
  34.     // Default max texture size of we can't get
  35.     // the info from the device caps.
  36.     m_dwMaxWidth = 1024;
  37.     m_dwMaxHeight = 1024;
  38. }
  39.  
  40.  
  41. void CNewTextureDlg::DoDataExchange(CDataExchange* pDX)
  42. {
  43.     CDialog::DoDataExchange(pDX);
  44.     //{{AFX_DATA_MAP(CNewTextureDlg)
  45.     DDX_Radio(pDX, IDC_TEXTURE, m_iTexType);
  46.     DDX_Text(pDX, IDC_WIDTH, m_dwWidth);
  47.     DDV_MinMaxInt(pDX, m_dwWidth, 1, m_dwMaxWidth);
  48.     DDX_Text(pDX, IDC_HEIGHT, m_dwHeight);
  49.     DDV_MinMaxInt(pDX, m_dwHeight, 1, m_dwMaxHeight);
  50.     DDX_Text(pDX, IDC_DEPTH, m_dwDepth);
  51.     DDV_MinMaxInt(pDX, m_dwDepth, 2, 1024);
  52.     DDX_CBIndex(pDX, IDC_D3DFMT_COMBO, m_iFmt );
  53.     DDX_Text(pDX, IDC_FMTDESC, m_strFmtDesc);
  54.     DDX_Text(pDX, IDC_MIPCOUNT, m_numMips);
  55.     DDV_MinMaxInt(pDX, m_numMips, 1, 20);
  56.     //}}AFX_DATA_MAP
  57. }
  58.  
  59.  
  60. BEGIN_MESSAGE_MAP(CNewTextureDlg, CDialog)
  61.     //{{AFX_MSG_MAP(CNewTextureDlg)
  62.     ON_BN_CLICKED(IDC_TEXTURE, OnChangeTextureType)
  63.     ON_BN_CLICKED(IDC_VOLUMETEXTURE, OnChangeTextureType)
  64.     ON_BN_CLICKED(IDC_CUBEMAP, OnChangeTextureType)
  65.     ON_CBN_SELCHANGE(IDC_D3DFMT_COMBO, OnChangeFormat)
  66.     //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CNewTextureDlg message handlers
  71.  
  72. BOOL CNewTextureDlg::OnInitDialog() 
  73. {
  74.     CDialog::OnInitDialog();
  75.     
  76.     CComboBox *pComboBox = (CComboBox*) GetDlgItem(IDC_D3DFMT_COMBO);
  77.     TCHAR strFmtLabel[MAX_PATH] = {0}; 
  78.     
  79.     for( int i = 0; i < fmtInfoArraySize; i++ )
  80.     {
  81.         // Construct the texture label
  82.         _sntprintf( strFmtLabel, MAX_PATH-1, TEXT("%s %i-bit: %s"),
  83.                     fmtInfoArray[i].strType,
  84.                     fmtInfoArray[i].nBitsPerTexel,
  85.                     fmtInfoArray[i].strName );
  86.  
  87.         // Add the label to the combo box
  88.         pComboBox->AddString(strFmtLabel);
  89.         
  90.         // Set default selection to A8R8G8B8
  91.         if( fmtInfoArray[i].fmt == D3DFMT_A8R8G8B8 )
  92.             pComboBox->SetCurSel( i );
  93.     }
  94.  
  95.     OnChangeTextureType();
  96.     OnChangeFormat();
  97.  
  98.     return TRUE;  // return TRUE unless you set the focus to a control
  99.                   // EXCEPTION: OCX Property Pages should return FALSE
  100. }
  101.  
  102.  
  103. void CNewTextureDlg::OnChangeTextureType() 
  104. {
  105.     UpdateData(TRUE);
  106.  
  107.     if (m_iTexType == 2)
  108.     {
  109.         // Volume Tex
  110.         GetDlgItem(IDC_VOLUMEDEPTHLABEL)->EnableWindow(TRUE);
  111.         GetDlgItem(IDC_DEPTH)->EnableWindow(TRUE);
  112.     }
  113.     else
  114.     {
  115.         // Normal or Cube Tex
  116.         GetDlgItem(IDC_VOLUMEDEPTHLABEL)->EnableWindow(FALSE);
  117.         GetDlgItem(IDC_DEPTH)->EnableWindow(FALSE);
  118.     }
  119.     UpdateData(FALSE);
  120.     OnChangeFormat();
  121. }
  122.  
  123.  
  124.  
  125. void CNewTextureDlg::OnChangeFormat() 
  126. {
  127.     UpdateData(TRUE);
  128.     m_fmt = fmtInfoArray[m_iFmt].fmt;
  129.     m_strFmtDesc.LoadString(fmtInfoArray[m_iFmt].idsFmtDesc);
  130.     UpdateData(FALSE);
  131. }
  132.  
  133. void CNewTextureDlg::OnOK() 
  134. {
  135.     UpdateData(TRUE);
  136.  
  137.     // TODO: Need to do lots of validation of width/height/depth/mipcount here
  138.  
  139.     if (m_iTexType != 2)
  140.         m_dwDepth = 0;
  141.  
  142.     m_fmt = fmtInfoArray[m_iFmt].fmt;
  143.  
  144.     CDialog::OnOK();
  145. }
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CCubeMapDlg dialog
  149.  
  150.  
  151. CCubeMapDlg::CCubeMapDlg(CWnd* pParent /*=NULL*/)
  152.     : CDialog(CCubeMapDlg::IDD, pParent)
  153. {
  154.     //{{AFX_DATA_INIT(CCubeMapDlg)
  155.     m_iFace = 0;
  156.     //}}AFX_DATA_INIT
  157. }
  158.  
  159.  
  160. void CCubeMapDlg::DoDataExchange(CDataExchange* pDX)
  161. {
  162.     CDialog::DoDataExchange(pDX);
  163.     //{{AFX_DATA_MAP(CCubeMapDlg)
  164.     DDX_Radio(pDX, IDC_POSX, m_iFace);
  165.     //}}AFX_DATA_MAP
  166. }
  167.  
  168.  
  169. BEGIN_MESSAGE_MAP(CCubeMapDlg, CDialog)
  170.     //{{AFX_MSG_MAP(CCubeMapDlg)
  171.         // NOTE: the ClassWizard will add message map macros here
  172.     //}}AFX_MSG_MAP
  173. END_MESSAGE_MAP()
  174.  
  175.  
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CVolumeMapDlg dialog
  178.  
  179.  
  180. CVolumeMapDlg::CVolumeMapDlg(CWnd* pParent /*=NULL*/)
  181.     : CDialog(CVolumeMapDlg::IDD, pParent)
  182. {
  183.     //{{AFX_DATA_INIT(CVolumeMapDlg)
  184.     m_powLayers = 0;
  185.     //}}AFX_DATA_INIT
  186. }
  187.  
  188.  
  189. void CVolumeMapDlg::DoDataExchange(CDataExchange* pDX)
  190. {
  191.     CDialog::DoDataExchange(pDX);
  192.     //{{AFX_DATA_MAP(CVolumeMapDlg)
  193.     DDX_Radio(pDX, IDC_RADIO2, m_powLayers);
  194.     //}}AFX_DATA_MAP
  195. }
  196.  
  197.  
  198. BEGIN_MESSAGE_MAP(CVolumeMapDlg, CDialog)
  199.     //{{AFX_MSG_MAP(CVolumeMapDlg)
  200.         // NOTE: the ClassWizard will add message map macros here
  201.     //}}AFX_MSG_MAP
  202. END_MESSAGE_MAP()
  203.  
  204. /////////////////////////////////////////////////////////////////////////////
  205. // CVolumeMapDlg message handlers
  206.  
  207.  
  208. /////////////////////////////////////////////////////////////////////////////
  209. // CChangeFmtDlg dialog
  210.  
  211.  
  212. CChangeFmtDlg::CChangeFmtDlg(CWnd* pParent /*=NULL*/)
  213.     : CDialog(CChangeFmtDlg::IDD, pParent)
  214. {
  215.     //{{AFX_DATA_INIT(CChangeFmtDlg)
  216.     m_iFmt = -1;
  217.     m_strFmtDesc = _T("");
  218.     //}}AFX_DATA_INIT
  219. }
  220.  
  221.  
  222. void CChangeFmtDlg::DoDataExchange(CDataExchange* pDX)
  223. {
  224.     CDialog::DoDataExchange(pDX);
  225.     //{{AFX_DATA_MAP(CChangeFmtDlg)
  226.     DDX_CBIndex(pDX, IDC_D3DFMT_COMBO, m_iFmt );
  227.     DDX_Text(pDX, IDC_FMTDESC, m_strFmtDesc);
  228.     //}}AFX_DATA_MAP
  229.  
  230.     GetDlgItem( IDOK )->EnableWindow( m_iFmt != m_iFmtInitial );
  231. }
  232.  
  233.  
  234. BEGIN_MESSAGE_MAP(CChangeFmtDlg, CDialog)
  235.     //{{AFX_MSG_MAP(CChangeFmtDlg)
  236.     ON_CBN_SELCHANGE(IDC_D3DFMT_COMBO, OnChangeFmt)
  237.     //}}AFX_MSG_MAP
  238. END_MESSAGE_MAP()
  239.  
  240. /////////////////////////////////////////////////////////////////////////////
  241. // CChangeFmtDlg message handlers
  242.  
  243. BOOL CChangeFmtDlg::OnInitDialog() 
  244. {
  245.     CDialog::OnInitDialog();
  246.  
  247.     CComboBox *pComboBox = (CComboBox*) GetDlgItem(IDC_D3DFMT_COMBO);
  248.     TCHAR strFmtLabel[MAX_PATH] = {0}; 
  249.         
  250.     for( int i = 0; i < fmtInfoArraySize; i++ )
  251.     {
  252.         // Create the texture label
  253.         _sntprintf( strFmtLabel, MAX_PATH-1, TEXT("%s %i-bit: %s"),
  254.                     fmtInfoArray[i].strType,
  255.                     fmtInfoArray[i].nBitsPerTexel,
  256.                     fmtInfoArray[i].strName );
  257.  
  258.         // Add the label to the combo box
  259.         pComboBox->AddString( strFmtLabel );
  260.  
  261.         // If the newly-added texture matches the current image format,
  262.         // store this index
  263.         if( m_fmt == fmtInfoArray[i].fmt )
  264.             m_iFmt = i;
  265.     }
  266.  
  267.     m_iFmtInitial = m_iFmt;
  268.  
  269.     UpdateFmtDesc();    
  270.     UpdateData(FALSE);
  271.  
  272.     return TRUE;  // return TRUE unless you set the focus to a control
  273.                   // EXCEPTION: OCX Property Pages should return FALSE
  274. }
  275.  
  276. void CChangeFmtDlg::OnChangeFmt() 
  277. {
  278.     UpdateData(TRUE);
  279.     UpdateFmtDesc();
  280. }
  281.  
  282. void CChangeFmtDlg::UpdateFmtDesc()
  283. {
  284.     m_fmt = fmtInfoArray[m_iFmt].fmt;
  285.     m_strFmtDesc.LoadString(fmtInfoArray[m_iFmt].idsFmtDesc);
  286.     UpdateData(FALSE);
  287. }
  288.  
  289. /////////////////////////////////////////////////////////////////////////////
  290. // CResizeDialog dialog
  291.  
  292.  
  293. CResizeDialog::CResizeDialog(CWnd* pParent /*=NULL*/)
  294.     : CDialog(CResizeDialog::IDD, pParent)
  295. {
  296.     //{{AFX_DATA_INIT(CResizeDialog)
  297.     m_newHeight = 0;
  298.     m_newWidth = 0;
  299.     m_oldHeight = _T("");
  300.     m_oldWidth = _T("");
  301.     //}}AFX_DATA_INIT
  302. }
  303.  
  304.  
  305. void CResizeDialog::DoDataExchange(CDataExchange* pDX)
  306. {
  307.     CDialog::DoDataExchange(pDX);
  308.     //{{AFX_DATA_MAP(CResizeDialog)
  309.     DDX_Text(pDX, IDC_NEWHEIGHT, m_newHeight);
  310.     DDV_MinMaxUInt(pDX, m_newHeight, 1, 4096);
  311.     DDX_Text(pDX, IDC_NEWWIDTH, m_newWidth);
  312.     DDV_MinMaxUInt(pDX, m_newWidth, 1, 4096);
  313.     DDX_Text(pDX, IDC_OLDHEIGHT, m_oldHeight);
  314.     DDX_Text(pDX, IDC_OLDWIDTH, m_oldWidth);
  315.     //}}AFX_DATA_MAP
  316. }
  317.  
  318.  
  319. BEGIN_MESSAGE_MAP(CResizeDialog, CDialog)
  320.     //{{AFX_MSG_MAP(CResizeDialog)
  321.     //}}AFX_MSG_MAP
  322. END_MESSAGE_MAP()
  323.